package com.ddwl.goods.dao;

import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.dao.TkDao;
import com.ddwl.goods.dao.mapper.LimitTimePurGoodMapper;
import com.ddwl.goods.dao.model.LimitTimePurGood;
import com.ddwl.schema.bo.goods.QueryLimitTimePurGoodBo;
import com.ddwl.schema.vo.order.OrderSpuVo;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.time.Instant;
import java.util.List;

/**
 * @author wenbin
 */
@Repository
public class LimitTimePurGoodDao extends TkDao<LimitTimePurGoodMapper, LimitTimePurGood> {


    /**
     * 更新活动商品
     * @param limitTimePurGood
     */
    public Integer updateGood(LimitTimePurGood limitTimePurGood){
        Example example = new Example(LimitTimePurGood.class);
        example.and().andEqualTo("itemId",limitTimePurGood.getItemId())
                .andEqualTo("limitActiveId",limitTimePurGood.getLimitActiveId());
        Integer i =baseMapper.updateByExampleSelective(limitTimePurGood,example);
        return i;
    }

    public List<LimitTimePurGood> queryGood(QueryLimitTimePurGoodBo bo) {
        return baseMapper.queryGood(bo);
    }

    public void updateOrderCount(List<OrderSpuVo> bo) {
        baseMapper.updateOrderCount(bo);
    }
    public void downOrderCount(List<OrderSpuVo> bo) {
        baseMapper.downOrderCount(bo);
    }

    public void updateViewCount(String itemId, String limitActiveId) {
        baseMapper.updateViewCount(itemId,limitActiveId);
    }


    public void deleteByBarcode(String barcode) {
        LimitTimePurGood model = new LimitTimePurGood();
        model.setGmtModified(Instant.now());
        model.setIsEffect(0);
        model.setDflag(BaseEnum.DflagEnum.DELETED.getCode());
        Example example = new Example(LimitTimePurGood.class);
        example.and().andEqualTo("barcode",barcode);
        baseMapper.updateByExampleSelective(model,example);
    }


    public String checkItemRepeat() {
        return baseMapper.checkItemRepeat();
    }

}
